import radar
from faker import Faker
from random import randint
import datetime
import uuid

def get_rand_row(category_list):
    max_num = len(category_list)
    min_num = 2
    flag = True
    while flag:
        num = randint(min_num, max_num)
        id = int(category_list[num]['资产编号'])
        if id % 100 !=0 :
            flag = False
    
    
    row_dic = dict()
    row_dic['A'] = id
    row_dic['B'] = category_list[num]['国标大类']
    row_dic['C'] = get_goods_name(category_list[num]['资产名称'])
    row_dic['F'] = get_num()
    row_dic['G'] = get_value(id)
    row_dic['H'] = row_dic['F'] * row_dic['G'] 
    row_dic['I'] = get_methon()
    row_dic['J'] = get_status()
    row_dic['K'] = get_partment()
    row_dic['L'] = get_partment()
    row_dic['M'] = get_where()
    row_dic['N'] = get_name()
    row_dic['p'] = get_name()
    dat = get_rand_date()
    row_dic['Q'] = str(dat)
    row_dic['S'] = get_zhejiu_status()
    row_dic['T'] = get_zhejiu_methon()
    row_dic['U'] = get_zhejiu_year(dat)
    
    return row_dic

def get_rand_date():

    datetime = radar.random_datetime(start='2000-01-01', stop='2022-10-29')

    return datetime

def get_num():
    i = randint(1, 10)
    if 5< i <= 8:
        return 2
    else:
        if i > 8:
            return 3
        else:
            return 1

def get_value(id):
    if str(id)[0] in set(['1', '4', '6']):
        return None
    if str(id)[0] in set(['2', '3']):
        i = randint(1, 1000)
        if i < 50:
            return randint(1000, 2000)
        else: 
            if i >=50 and i < 300:
                return randint(500, 1000)
            else:
                return randint(100, 500)

def get_methon():
    i = randint(1, 10)
    if i < 3:
        return '新购'
    else:
        return '调拨'

def get_status():
    i = randint(1, 10)
    if i < 3:
        return '在用'
    else:
        return '在库'

def get_partment():
    partment =['办公室','综合处','政策法规处','自然资源调查监测处','自然资源确权登记处','自然资源所有者权益处',\
        '自然资源开发利用处','重点规划处','总体规划处','交通规划处','文化风貌处','城市规划处','建筑规划处',\
        '市政规划处','村镇规划处','国土空间用途管制处','国土空间生态修复处','耕地保护监督处','地质勘查管理处',\
        '矿业权管理处','矿产资源保护监督处','测绘管理处','地理信息管理处','规划和自然资源督察处',\
        '科技与信息化处','信访与政务公开处','计划财务处','审计处','干部人事处']

    length = len(partment)
    i = randint(0, length - 1)

    return partment[i]

def get_where():
    if randint(0, 10) < 9:
        return str(randint(0, 6)) + str(randint(10, 60))
    else:
        return str(randint(0, 6)) + '0' + str(randint(0, 9))

def get_name():
    fake = Faker('zh_CN')
    return fake.name()

def get_goods_name(name):
    name_lib = ['盛荣','润格','友庆','利友','虹昌','伟君','骏虹','盈裕','中江',\
        '河嘉','衡纳','诚鼎','盈优','佳艾','鹏雄','梁启','友玮','冠桦','茂德',\
        '彦金','泰图','健楠','久亦','振伦','皓立','骏明','雄杭','艾光','麟格',\
        '冠森','永佳','海鑫','力盛','艾齐','宏卫','博桦','畅信','泰雨','润森',\
        '丰骏','希才','烽昌','诚楚','旭霖','荣帆','意河','久邦','诚德','奕群',\
        '柏恒','智顺','雄齐','熙智','玮朗','迅丰','广乐','中奕','翔迅','坚勤',\
        '德伊','强星','新力','强俊','信力','腾基','田峰','盈成','骏秦','畅业',\
        '坤博','强海','祥曦','源优','力盈','信杭','彦彦','领伊','嘉久','欧亚',\
        '锦雨','久瑄','思博','乐领','凯驰','浚坤','学齐','智梁','畅达','嘉翰',\
        '瀚尚','杰达','恩坤','喜杭','伟言','茂涛','阳春','阳恒','邦诚','才杰',\
        '柏邦','信信','希沃','迅玮','江恒','庆雷','颂云','海纶','弘金','航通',\
        '鑫森','立彦','格博','艾柏','富领','思峻','晏联','兴明','星亿','奕同',\
        '宇榕','毅亚','森盛','卫森','信正','健江','隆耀','豪学','昌利','纳才',\
        '梁安','德威','领虹','弘炫','诚昌','领兴','勤海','永文','瀚星','维利',\
        '楠霖','景庆','帆俊','江昂','星风','富思','贤光','渝河','升豪','盈腾',\
        '雷诚','雷海','锦熙','力诚','财帆','腾峻','建昂','鼎中','圣力','虹晨',\
        '岩兆','欧信','蓝华','枫同','聪耀','健诚','冠旭','洋博','盈润','朗玮',\
        '斌纶','星玮','锦海','亿鼎','明楚','佰阳','丰晟','梁利','达宏','熙滨',\
        '俊江','佰龙','龙勤','威秋','丰志','冠恒','联文','春斌','信兆','信裕',\
        '禾坚','天智','滨尊','佑文','楚杉','安澄','虹景','联京','秦炫','桦春',\
        '启景','杉泰','森尚','虹熙','驰鑫','咏晏','峰若','洁杰','宏富','富衡',\
        '业承','秦建','冠琛','秦皓','昂道','威洁','秋朗','思诚','卓旭','途尊',\
        '源嘉','仁乐','诚佳','言启','岩聪','晏汉','灿天','庆铭','宸宸','东晏',\
        '新讯','峻颂','若喜','天元','帆永','浚弘','腾彩','宁建','顺尚','霖泰',\
        '浩衡','秦金','昌欧','森源','晨久','晨天','阳炫','茂蓝','钧昌','阳茂',\
        '文博','熙云','卓榕','威亮','金希','辰澄','力博','君广','天谦','宸星',\
        '凯茂','亚世','枫博','平龙','弘广','河咏','海虹','澄吉','虹浚','仟同',\
        '隆宁','渝田','成尊','浩晟','同富','意维','博强','基群','致朗','振仲','阳艾']

    length = len(name_lib)
    last_name = '_' + name_lib[randint(0, length)] + '_' + str(uuid.uuid4())[0:randint(2, 3)]
    return name + last_name

def get_zhejiu_status():
    i = randint(0, 10)
    if i > 8: 
        return '已折旧'
    else:
        return '未折旧' 

def get_zhejiu_methon():
    return '平均年限法'

def get_zhejiu_year(date):
    today = datetime.date.today()

    year_1 = date.strftime('%Y')
    month_1 = date.strftime('%m')
    year_2 = today.strftime('%Y')
    month_2 = today.strftime('%m')
    
    return (int(year_2) - int(year_1)) * 12 + int(month_2) - int(month_1)

def get_shenhe_status():
    i = randint(0, 1000)
    if i > 990 :
        return '已审核'
    else :
        return '未审核'